Static Methods

The following static methods are available globally.

  • You can register a tracer to monitor the performance of all SQLs.
    It returns

    1. The collection of SQLs and the executions count of each SQL.
    2. Time consuming in nanoseconds.
    3. Tag of database.

    Note that:

    1. You should register trace before all db operations.
    2. Global tracer will be recovered by db tracer.

      Database.globalTrace(ofPerformance: { (tag, sqls, cost) in if let wrappedTag = tag { print(Tag: \(wrappedTag)) }else { print(Nil tag) } sqls.forEach({ (arg) in print(SQL: \(arg.key) Count: \(arg.value)) }) print(Total cost \(cost) nanoseconds) })

    Tracer may cause wcdb performance degradation, according to your needs to choose whether to open.

    Declaration

    Swift

    public static func globalTrace(ofPerformance trace: @escaping PerformanceTracer)

    Parameters

    trace

    trace. Nil to disable global preformance trace.

  • You can register a tracer to monitor the execution of all SQLs.
    It returns a prepared or executed SQL.
    Note that you should register trace before all db operations.

    Database.globalTrace(ofSQL: { (sql) in
        print("SQL: \(sql)")
    })
    

    Tracer may cause wcdb performance degradation, according to your needs to choose whether to open.

    Declaration

    Swift

    public static func globalTrace(ofSQL trace: @escaping SQLTracer)

    Parameters

    trace

    trace. Nil to disable global sql trace.

  • You can register a reporter to monitor all errors.

    Database.globalTrace(ofError: { (error) in
        switch error.type {
        case .sqliteGlobal:
            debugPrint("[WCDB][DEBUG] \(error.description)")
        case .warning:
            print("[WCDB][WARNING] \(error.description)")
        default:
            print("[WCDB][ERROR] \(error.description)")
        }
     })
    

    Declaration

    Swift

    public static func globalTrace(ofError errorReporter: @escaping Error.Reporter)

    Parameters

    errorReporter

    report

  • Reset global error trace to default trace.

    Declaration

    Swift

    public static func resetGlobalTraceOfError()